import { queryGoodsDetail } from '@/services/goods';

export default {
  namespace: 'goods',
  state: {
    goodsInfo: {},
  },
  effects: {
    *fetchGoodsInfo({ payload }, { call, put }) {
      const response = yield call(queryGoodsDetail, payload);
      yield put({
        type: 'saveGoodsInfo',
        payload: response.data,
      });
    },
  },

  reducers: {
    saveGoodsInfo(state, action) {
      return {
        ...state,
        goodsInfo: action.payload,
      };
    },
  },
};
